<!--
 * @Description:
 * @FilePath: \rs_wms_pc\src\views\storehouse\checkPlan\locationDialog.vue
-->
<template>
    <el-dialog v-if="open" :title="title" :visible.sync="open" width="70vw" append-to-body>
        <div>
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px" @submit.native.prevent>
                <el-form-item label="库位" prop="no">
                    <el-input
                    v-model="queryParams.no"
                    placeholder="请输入库位"
                    clearable
                    @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>

            <el-table v-loading="loading" :data="locationList" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" align="center" />
                <af-table-column label="仓库编号" align="center" prop="storehouseNo" />
                <af-table-column label="仓库名称" align="center" prop="storehouseName" />
                <af-table-column label="库区编号" align="center" prop="storehouseAreaNo" />
                <af-table-column label="库区名称" align="center" prop="storehouseAreaName" />
                <af-table-column label="库位编号" align="center" prop="no" />
                <af-table-column label="库位名称" align="center" prop="name" />
            </el-table>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submit">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { listLocation } from "@/api/basic/location";

export default {
  name: "locationDialog",
  props:{
      title:{
          type: String,
          default:'请选择'
      },
      query:{
          type: Object,
          default:()=>{}
      }
  },
  data(){
      return{
          loading:false,
          open:false,
          locationList:[],
          selectionList:[],
          queryParams:{}
      }
  },
  created() {
  },
  methods:{
    init(){
      this.reset();
      this.getList();
      this.open = true;
    },
    /** 查询库位主数据列表  */
    getList() {
      this.loading = true;
      listLocation({...this.query, ...this.queryParams}).then(response => {
        this.locationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
        this.selectionList = selection
    //   this.ids = selection.map(item => item.id)
    //   this.single = selection.length!==1
    //   this.multiple = !selection.length
    },
    submit(){
        this.$emit("selectChange", this.selectionList)
        this.cancel()
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.queryParams = {
        name: null,
      };
      this.resetForm("queryForm");
    },
  }

}
</script>
